package asg.pp;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
import controller.Controller;

public class PurblePlaceService extends Controller {

	/**
	 * Activity
	 **/
	private GameActivities gameActivity;
	private MainActivity mainActivity;
	private ArrayList<User> userList;
	private static final PurblePlaceService service = new PurblePlaceService();

	public static final PurblePlaceService getInstance() {
		return service;
	}
	
	public void login(GameActivities act, String userId) {
		gameActivity = act;
		super.login(userId);
		super.start();
	}

	public void startUpUi() {
		gameActivity.loadMainInterface();
	}
	
	public void onClick(int id) {
		Log.i("service", "aaa");
		Log.i("service", "id: " + id + " state: " + getCurrentState());
		if (getCurrentState() == Controller.ACTIVE)
			selectImage(id);
	}

	public void startGame() {
		Log.i("Service line 45", "game is starting");
		if(getCurrentState() == Controller.WAITSTART) 
			super.startGame();
	}

	public void quitGame(Context context) {
		Log.i("57", "service: quit game");
		// TODO Confirm dialog
//		exitGame();
	}
	
	public void setUpdateUser(String rcv) {

		if (rcv.startsWith("updateuser")) {
            Log.i("55", "updating... user");
            Log.i("56", rcv);
            
            String strUsers = rcv.split(" ")[1];
            String[] userIds = strUsers.split("-");

            userList.clear();			//Remove all current user
            for (String userId : userIds) {		//Update all user
                userList.add(new User(userId));
                Log.i("69", "User online: " + userId);
            }
            
            
        }

    }
}
